## Baccaro and Rei 2007 IO

library(foreign) 
library(Amelia)
library(mi)
library(hot.deck)
library(mice)
library(mirt)
library(miceadds)

## Load original dataset
br2007 <- read.dta("BR2007 IO Rep Data.dta")
head(br2007)
dim(br2007)

# Drop ID vars
br2007$country <- br2007$cntry <- br2007$ctyn <- br2007$cty <- NULL

## Derived dummy vars
br2007$td1 <- br2007$td2 <- br2007$td3 <- br2007$td4 <- br2007$td5 <- br2007$td6 <- br2007$td7 <- br2007$td8 <- br2007$td9 <- br2007$td10 <- br2007$td11 <- br2007$td12 <- br2007$td13 <- br2007$td14 <- br2007$td15 <- br2007$td16 <- br2007$td17 <- br2007$td18 <- br2007$td19 <- br2007$td20 <- br2007$td21 <- br2007$td22 <- br2007$td23 <- br2007$td24 <- br2007$td25 <- br2007$td26 <- br2007$td27 <- br2007$td28 <- br2007$td29 <- br2007$td30 <- br2007$td31 <- br2007$td32 <- br2007$td33 <- br2007$td33 <- br2007$td34 <- br2007$td35 <- br2007$td36 <-br2007$td37 <- br2007$td38 <- br2007$td39 <- br2007$td40 <- br2007$td41 <- br2007$csdcpi1 <-br2007$csdcpi2 <-br2007$csdcpi3 <-br2007$csdcpi4 <-br2007$csdcpi5 <- br2007$csdcpi6 <- br2007$csdcpi7 <- br2007$csdcpi8 <- br2007$csdcpi9 <- br2007$csdcpi10 <- br2007$csdcpi11 <- br2007$csdcpi12 <- br2007$csdcpi13 <- br2007$csdcpi14 <- br2007$csdcpi15 <- br2007$csdcpi16 <- br2007$csdcpi17 <- br2007$csdcpi18 <- br2007$csdcpi19 <- br2007$csdcpi20 <- br2007$cstt1 <- br2007$cstt2 <- br2007$cstt3 <- br2007$cstt4 <- br2007$cstt5 <- br2007$cstt6 <- br2007$cstt7 <- br2007$cstt8 <- br2007$cstt9 <- br2007$cstt10 <- br2007$cstt11 <- br2007$cstt12 <- br2007$cstt13 <- br2007$cstt14 <- br2007$cstt15 <- br2007$cstt16 <- br2007$cstt17 <- br2007$cstt18 <- br2007$cstt19 <- br2007$cstt20 <- NULL

## Remove vars that do not vary
br2007$mep <- br2007$mud <- NULL

## How many variables? 236: reduction necessary
dim(br2007)

## Which variables are in analysis and have missing data?
sum(is.na(br2007 $unr))/nrow(br2007)*100
sum(is.na(br2007 $lunr))/nrow(br2007)*100
sum(is.na(br2007 $rir))/nrow(br2007)*100
sum(is.na(br2007 $perdcpi))/nrow(br2007)*100
sum(is.na(br2007 $tots))/nrow(br2007)*100
sum(is.na(br2007 $ldprod))/nrow(br2007)*100
sum(is.na(br2007 $ep))/nrow(br2007)*100
sum(is.na(br2007 $ud_alt))/nrow(br2007)*100
sum(is.na(br2007 $benOECD))/nrow(br2007)*100 ## N
sum(is.na(br2007 $tw_alt2))/nrow(br2007)*100 
sum(is.na(br2007 $cbi))/nrow(br2007)*100 ## N
sum(is.na(br2007 $kenwcoor))/nrow(br2007)*100 
sum(is.na(br2007 $Dev_K_UD))/nrow(br2007)*100
sum(is.na(br2007 $Dev_ken_tw))/nrow(br2007)*100
sum(is.na(br2007 $Dev_k_ep))/nrow(br2007)*100
sum(is.na(br2007 $Dev_k_benoecd))/nrow(br2007)*100
sum(is.na(br2007 $Dev_ken_cbi))/nrow(br2007)*100
sum(is.na(br2007 $ce2))/nrow(br2007)*100 ## N
sum(is.na(br2007 $ye2))/nrow(br2007)*100 ## N
sum(is.na(br2007 $brr_alt))/nrow(br2007)*100
sum(is.na(br2007 $Dev_k_brr))/nrow(br2007)*100
sum(is.na(br2007 $CNTRY))/nrow(br2007)*100 ## N
sum(is.na(br2007 $year))/nrow(br2007)*100 ## N

analysis <- as.data.frame(cbind(br2007$unr, br2007$lunr, br2007$rir, br2007$perdcpi, br2007$tots, br2007$ldprod, br2007$ep, br2007$ud_alt, br2007$tw_alt2, br2007$kenwcoor, br2007$Dev_K_UD, br2007$Dev_ken_tw, br2007$Dev_k_ep, br2007$Dev_k_benoecd, br2007$Dev_ken_cbi, br2007$brr_alt, br2007$Dev_k_brr))

missing <- as.data.frame(cbind(as.integer(complete.cases(br2007$unr)), as.integer(complete.cases(br2007$lunr)), as.integer(complete.cases(br2007$rir)), as.integer(complete.cases(br2007$perdcpi)), as.integer(complete.cases(br2007$tots)), as.integer(complete.cases(br2007$ldprod)), as.integer(complete.cases(br2007$ep)), as.integer(complete.cases(br2007$ud_alt)), as.integer(complete.cases(br2007$tw_alt2)), as.integer(complete.cases(br2007$kenwcoor)), as.integer(complete.cases(br2007$Dev_K_UD)), as.integer(complete.cases(br2007$Dev_ken_tw)), as.integer(complete.cases(br2007$Dev_k_ep)), as.integer(complete.cases(br2007$Dev_k_benoecd)), as.integer(complete.cases(br2007$Dev_ken_cbi)), as.integer(complete.cases(br2007$brr_alt)), as.integer(complete.cases(br2007$Dev_k_brr))))

dim(analysis)
dim(missing)
apply(missing, 2, sd)

## Remove analysis variables
## br2007$unr <- br2007$lunr <- br2007$rir <- br2007$perdcpi <- br2007$tots <- br2007$ldprod <- br2007$ep <- br2007$ud_alt <- br2007$tw_alt2 <- br2007$kenwcoor <- br2007$Dev_K_UD <- br2007$Dev_ken_tw <- br2007$Dev_k_ep <- br2007$Dev_k_benoecd <- br2007$Dev_ken_cbi <- br2007$brr_alt <- br2007$Dev_k_brr <- br2007$CNTRY <- br2007$ce <- br2007$Dev_k_brr <- NULL
## head(br2007)
## var(br2007)

 ## Check round(correlations and missing values
round(cor(br2007 $epop, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $epop, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $epop))/nrow(br2007)*100
## Y

round(cor(br2007 $lf_all, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $lf_all, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $lf_all))/nrow(br2007)*100
## N
br2007 $lf_all <- NULL

round(cor(br2007 $sur, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $sur, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $sur))/nrow(br2007)*100
## Y

round(cor(br2007 $prf, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $prf, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $prf))/nrow(br2007)*100
## N
br2007 $prf <- NULL

round(cor(br2007 $ud, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud))/nrow(br2007)*100
## N
br2007 $ud <- NULL

round(cor(br2007 $bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $brr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $brr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $brr))/nrow(br2007)*100
## Y

round(cor(br2007 $bd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bd))/nrow(br2007)*100
## N
br2007 $bd <- NULL

round(cor(br2007 $bd_alt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bd_alt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bd_alt))/nrow(br2007)*100
## N
br2007 $bd_alt <- NULL

round(cor(br2007 $tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $tw))/nrow(br2007)*100
## Y

round(cor(br2007 $tw_cor, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $tw_cor, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $tw_cor))/nrow(br2007)*100
## Y

round(cor(br2007 $tw_alt1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $tw_alt1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $tw_alt1))/nrow(br2007)*100
## Y

round(cor(br2007 $almp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $almp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $almp))/nrow(br2007)*100
## N
br2007 $almp <- NULL

round(cor(br2007 $ho, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ho, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ho))/nrow(br2007)*100
## N
br2007 $ho <- NULL

round(cor(br2007 $esi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $esi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $esi))/nrow(br2007)*100
## Y

round(cor(br2007 $prodw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $prodw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $prodw))/nrow(br2007)*100
## N
br2007 $prodw <- NULL

round(cor(br2007 $prod1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $prod1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $prod1))/nrow(br2007)*100
## N
br2007 $prod1 <- NULL

round(cor(br2007 $infl, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $infl, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $infl))/nrow(br2007)*100
## N
br2007 $infl <- NULL

round(cor(br2007 $open, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $open, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $open))/nrow(br2007)*100
## N
br2007 $open <- NULL

round(cor(br2007 $pim , analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $pim , missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $pim ))/nrow(br2007)*100
## Y

round(cor(br2007 $pex, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $pex, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $pex))/nrow(br2007)*100
## Y

round(cor(br2007 $tot, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $tot, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $tot))/nrow(br2007)*100
## N
br2007 $tot <- NULL

round(cor(br2007 $gap, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $gap, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $gap))/nrow(br2007)*100
## N
br2007 $gap <- NULL

round(cor(br2007 $gempl, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $gempl, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $gempl))/nrow(br2007)*100
## N
br2007 $gempl <- NULL

round(cor(br2007 $oil, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $oil, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $oil))/nrow(br2007)*100
## N
br2007 $oil <- NULL

round(cor(br2007 $usd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $usd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $usd))/nrow(br2007)*100
## N
br2007 $usd <- NULL

round(cor(br2007 $dpoil, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $dpoil, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $dpoil))/nrow(br2007)*100
## N
br2007 $dpoil <- NULL

round(cor(br2007 $sharp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $sharp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $sharp))/nrow(br2007)*100
## N
br2007 $sharp <- NULL

round(cor(br2007 $rsharp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $rsharp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $rsharp))/nrow(br2007)*100
## N
br2007 $rsharp <- NULL

round(cor(br2007 $bc1sq, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bc1sq, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bc1sq))/nrow(br2007)*100
## Y

round(cor(br2007 $bc2sq, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bc2sq, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bc2sq))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_ud, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_ud, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_ud))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_uda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_uda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_uda))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_br, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_br, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_br))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_bra, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_bra, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_bra))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_tw))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_twc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_twc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_twc))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_twa1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_twa1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_twa1))/nrow(br2007)*100
## Y

round(cor(br2007 $ep_twa2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ep_twa2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ep_twa2))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_br, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_br, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_br))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_bra, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_bra, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_bra))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_tw))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_twc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_twc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_twc))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_twa1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_twa1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_twa1))/nrow(br2007)*100
## Y

round(cor(br2007 $ud_twa2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $ud_twa2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $ud_twa2))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_br, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_br, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_br))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_bra, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_bra, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_bra))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_tw))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_twc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_twc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_twc))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_twa1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_twa1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_twa1))/nrow(br2007)*100
## Y

round(cor(br2007 $uda_twa2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uda_twa2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uda_twa2))/nrow(br2007)*100
## Y

round(cor(br2007 $br_tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $br_tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $br_tw))/nrow(br2007)*100
## Y

round(cor(br2007 $br_twc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $br_twc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $br_twc))/nrow(br2007)*100
## Y

round(cor(br2007 $br_twa1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $br_twa1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $br_twa1))/nrow(br2007)*100
## Y

round(cor(br2007 $br_twa2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $br_twa2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $br_twa2))/nrow(br2007)*100
## Y

round(cor(br2007 $bra_tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bra_tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bra_tw))/nrow(br2007)*100
## Y

round(cor(br2007 $bra_twc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bra_twc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bra_twc))/nrow(br2007)*100
## Y

round(cor(br2007 $bra_twa1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bra_twa1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bra_twa1))/nrow(br2007)*100
## Y

round(cor(br2007 $bra_twa2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bra_twa2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bra_twa2))/nrow(br2007)*100
## Y

round(cor(br2007 $br_bd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $br_bd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $br_bd))/nrow(br2007)*100
## N
br2007 $br_bd <- NULL

round(cor(br2007 $bra_bd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bra_bd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bra_bd))/nrow(br2007)*100
## N
br2007 $bra_bd <- NULL

round(cor(br2007 $br_bda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $br_bda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $br_bda))/nrow(br2007)*100
## N
br2007 $br_bda <- NULL

round(cor(br2007 $bra_bda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $bra_bda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $bra_bda))/nrow(br2007)*100
## N
br2007 $bra_bda <- NULL

round(cor(br2007 $twc_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $twc_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $twc_bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $twc_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $twc_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $twc_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $twa1_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $twa1_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $twa1_bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $twa1_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $twa1_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $twa1_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $twa2_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $twa2_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $twa2_bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $twa2_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $twa2_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $twa2_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $Lunr_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Lunr_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Lunr_bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $Lunr_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Lunr_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Lunr_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $Lunr_br, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Lunr_br, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Lunr_br))/nrow(br2007)*100
## Y

round(cor(br2007 $Lunr_bra, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Lunr_bra, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Lunr_bra))/nrow(br2007)*100
## Y

round(cor(br2007 $cbi_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $cbi_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $cbi_bc1))/nrow(br2007)*100
## N
br2007 $cbi_bc1 <- NULL

round(cor(br2007 $cbi_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $cbi_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $cbi_bc2))/nrow(br2007)*100
## N
br2007 $cbi_bc2 <- NULL

round(cor(br2007 $esi_bc1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $esi_bc1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $esi_bc1))/nrow(br2007)*100
## Y

round(cor(br2007 $esi_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $esi_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $esi_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $dprod, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $dprod, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $dprod))/nrow(br2007)*100
## N
br2007 $dprod <- NULL

round(cor(br2007 $Ltots, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Ltots, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Ltots))/nrow(br2007)*100
## N
br2007 Ltots prf <- NULL

round(cor(br2007 $almpu, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $almpu, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $almpu))/nrow(br2007)*100
## N
br2007 $almpu <- NULL

round(cor(br2007 $u7779, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $u7779, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $u7779))/nrow(br2007)*100
## N
br2007 $u7779 <- NULL

round(cor(br2007 $almpu_iv, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $almpu_iv, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $almpu_iv))/nrow(br2007)*100
## N
br2007 $almpu_iv <- NULL

round(cor(br2007 $d90s, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $d90s, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $d90s))/nrow(br2007)*100
## N
br2007 $d90s <- NULL

round(cor(br2007 $tt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $tt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $tt))/nrow(br2007)*100
## Y

round(cor(br2007 $dcpi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $dcpi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $dcpi))/nrow(br2007)*100
## N
br2007 $dcpi <- NULL

round(cor(br2007 $euro4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $euro4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $euro4))/nrow(br2007)*100
## N
br2007 $euro4 <- NULL

round(cor(br2007 $euroarea, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $euroarea, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $euroarea))/nrow(br2007)*100
## N
br2007 $euroarea <- NULL

round(cor(br2007 $eurooecd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $eurooecd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $eurooecd))/nrow(br2007)*100
## N
br2007 $eurooecd <- NULL

round(cor(br2007 $lf_wgt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $lf_wgt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $lf_wgt))/nrow(br2007)*100
## N
br2007 $lf_wgt <- NULL

round(cor(br2007 $selez1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $selez1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $selez1))/nrow(br2007)*100
## N
br2007 $selez1 <- NULL

round(cor(br2007 $uecov, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $uecov, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $uecov))/nrow(br2007)*100
## N
br2007 $uecov <- NULL

round(cor(br2007 $wbrr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $wbrr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $wbrr))/nrow(br2007)*100
## Y

round(cor(br2007 $wbrr_alt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $wbrr_alt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $wbrr_alt))/nrow(br2007)*100
## Y

round(cor(br2007 $wbd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $wbd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $wbd))/nrow(br2007)*100
## N
br2007 $wbd <- NULL

round(cor(br2007 $wbd_alt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $wbd_alt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $wbd_alt))/nrow(br2007)*100
## N
br2007 $wbd_alt <- NULL

round(cor(br2007 $mlunr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mlunr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mlunr))/nrow(br2007)*100
## N
br2007 $mlunr <- NULL

round(cor(br2007 $mbc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mbc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mbc2))/nrow(br2007)*100
## N
br2007 $mbc2 <- NULL

round(cor(br2007 $mbr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mbr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mbr))/nrow(br2007)*100
## N
br2007 $mbr <- NULL

round(cor(br2007 $mcbi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mcbi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mcbi))/nrow(br2007)*100
## N
br2007 $mcbi <- NULL

round(cor(br2007 $Dev_ep_ud, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_ep_ud, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_ep_ud))/nrow(br2007)*100
## N
br2007 $Dev_ep_ud <- NULL

round(cor(br2007 $mtw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mtw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mtw))/nrow(br2007)*100
## N
br2007 $mtw <- NULL

round(cor(br2007 $Dev_ud_tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_ud_tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_ud_tw))/nrow(br2007)*100
## N
br2007 $Dev_ud_tw <- NULL

round(cor(br2007 $Dev_Lunr_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_Lunr_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_Lunr_bc2))/nrow(br2007)*100
## N
br2007 $Dev_Lunr_bc2 <- NULL

round(cor(br2007 $Dev_Lunr_brr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_Lunr_brr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_Lunr_brr))/nrow(br2007)*100
## N
br2007 $Dev_Lunr_brr <- NULL

round(cor(br2007 $Dev_cbi_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_cbi_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_cbi_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $Dev_ep_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_ep_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_ep_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $Dev_ud_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_ud_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_ud_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $Dev_brr_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_brr_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_brr_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $Dev_tw_bc2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_tw_bc2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_tw_bc2))/nrow(br2007)*100
## Y

round(cor(br2007 $tbkcoor, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $tbkcoor, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $tbkcoor))/nrow(br2007)*100
## N
br2007 $tbkcoor <- NULL

round(cor(br2007 $compup, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $compup, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $compup))/nrow(br2007)*100
## N
br2007 $compup <- NULL

round(cor(br2007 $tbkup, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $tbkup, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $tbkup))/nrow(br2007)*100
## N
br2007 $tbkup <- NULL

round(cor(br2007 $D_unr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_unr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_unr))/nrow(br2007)*100
## N
br2007 $D_unr <- NULL

round(cor(br2007 $D_ep, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_ep, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_ep))/nrow(br2007)*100
## N
br2007 $D_ep <- NULL

round(cor(br2007 $D_ud_alt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_ud_alt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_ud_alt))/nrow(br2007)*100
## N
br2007 $D_ud_alt <- NULL

round(cor(br2007 $d_tw_alt2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $d_tw_alt2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $d_tw_alt2))/nrow(br2007)*100
## N
br2007 $d_tw_alt2 <- NULL

round(cor(br2007 $D_rir, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_rir, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_rir))/nrow(br2007)*100
## N
br2007 $D_rir <- NULL

round(cor(br2007 $d_bra_bda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $d_bra_bda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $d_bra_bda))/nrow(br2007)*100
## N
br2007 $d_bra_bda <- NULL

round(cor(br2007 $d_dcpi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $d_dcpi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $d_dcpi))/nrow(br2007)*100
## Y

round(cor(br2007 $d_tbkup, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $d_tbkup, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $d_tbkup))/nrow(br2007)*100
## N
br2007 $d_tbkup <- NULL

round(cor(br2007 $d_cbi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $d_cbi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $d_cbi))/nrow(br2007)*100
## N
br2007 $d_cbi <- NULL

round(cor(br2007 $D_lunr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_lunr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_lunr))/nrow(br2007)*100
## N
br2007 $D_lunr <- NULL

round(cor(br2007 $D_ldprod, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_ldprod, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_ldprod))/nrow(br2007)*100
## Y

round(cor(br2007 $D_tots, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_tots, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_tots))/nrow(br2007)*100
## Y

round(cor(br2007 $mbrr_alt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mbrr_alt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mbrr_alt))/nrow(br2007)*100
## N
br2007 $mbrr_alt <- NULL

round(cor(br2007 $mbda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mbda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mbda))/nrow(br2007)*100
## N
br2007 $mbda <- NULL

round(cor(br2007 $Dev_bda_brr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_bda_brr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_bda_brr))/nrow(br2007)*100
## N
br2007 $Dev_bda_brr <- NULL

round(cor(br2007 $mud1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mud1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mud1))/nrow(br2007)*100
## N
br2007 $mud1 <- NULL

round(cor(br2007 $mkenw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mkenw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mkenw))/nrow(br2007)*100
## N
br2007 $mkenw <- NULL

round(cor(br2007 $mtwa, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mtwa, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mtwa))/nrow(br2007)*100
## N
br2007 $mtwa <- NULL

round(cor(br2007 $mep1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mep1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mep1))/nrow(br2007)*100
## N
br2007 $mep1 <- NULL

round(cor(br2007 $mbrra, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mbrra, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mbrra))/nrow(br2007)*100
## N
br2007 $mbrra <- NULL

round(cor(br2007 $Dev_k_bba, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_k_bba, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_k_bba))/nrow(br2007)*100
## Y

round(cor(br2007 $Dev_k_bda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $Dev_k_bda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $Dev_k_bda))/nrow(br2007)*100
## Y

round(cor(br2007 $D_brr_alt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_brr_alt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_brr_alt))/nrow(br2007)*100
## N
br2007 $D_brr_alt <- NULL

round(cor(br2007 $D_bd_alt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_bd_alt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_bd_alt))/nrow(br2007)*100
## N
br2007 $D_bd_alt <- NULL

round(cor(br2007 $D_bda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_bda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_bda))/nrow(br2007)*100
## N
br2007 $D_bda <- NULL

round(cor(br2007 $D_Dev_bda_brr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_bda_brr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_bda_brr))/nrow(br2007)*100
## N
br2007 $D_Dev_bda_brr <- NULL

round(cor(br2007 $D_tw_alt2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_tw_alt2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_tw_alt2))/nrow(br2007)*100
## N
br2007 $D_tw_alt2 <- NULL

round(cor(br2007 $D_cbi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_cbi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_cbi))/nrow(br2007)*100
## N
br2007 $D_cbi <- NULL

round(cor(br2007 $D_kenwcoor, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_kenwcoor, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_kenwcoor))/nrow(br2007)*100
## N
br2007 $D_kenwcoor <- NULL

round(cor(br2007 $D_Dev_K_UD, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_K_UD, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_K_UD))/nrow(br2007)*100
## N
br2007 $D_Dev_K_UD <- NULL

round(cor(br2007 $D_Dev_ken_tw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_ken_tw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_ken_tw))/nrow(br2007)*100
## N
br2007 $D_Dev_ken_tw <- NULL

round(cor(br2007 $D_Dev_k_ep, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_k_ep, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_k_ep))/nrow(br2007)*100
## N
br2007 $D_Dev_k_ep <- NULL

round(cor(br2007 $D_Dev_k_brr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_k_brr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_k_brr))/nrow(br2007)*100
## N
br2007 $D_Dev_k_brr <- NULL

round(cor(br2007 $D_Dev_k_bda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_k_bda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_k_bda))/nrow(br2007)*100
## N
br2007 $D_Dev_k_bda <- NULL

round(cor(br2007 $D_Dev_ken_cbi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_ken_cbi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_ken_cbi))/nrow(br2007)*100
## N
br2007 $D_Dev_ken_cbi <- NULL

round(cor(br2007 $D_benOECD, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_benOECD, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_benOECD))/nrow(br2007)*100
## N
br2007 $D_benOECD <- NULL

round(cor(br2007 $mbenoecd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $mbenoecd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $mbenoecd))/nrow(br2007)*100
## N
br2007 $mbenoecd <- NULL

round(cor(br2007 $D_Dev_k_benoecd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(br2007 $D_Dev_k_benoecd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(br2007 $D_Dev_k_benoecd))/nrow(br2007)*100
## N
br2007 $D_Dev_k_benoecd <- NULL

## Imputation
dim(br2007)

## What is average percentage of missing data?
NAs <- function(x) {
    as.vector(apply(x, 2, function(x) length(which(is.na(x)))))
    }
NAs(br2007)/nrow(br2007)
mean(NAs(br2007)/nrow(br2007))*100

## Thus: 5 imputations

set.seed(02138)
br2007.out <- amelia(br2007, m = 5, cs = "CNTRY", ts = "year", polytime = 3, lags = c("ep", "ud_alt", "brr_alt", "tw_alt2", "cbi", "kenwcoor", "benOECD", "unr"), empri = 0.01*nrow(br2007))

write.amelia(obj=br2007.out, file.stem = "BR2007 IO Imp Data", format = "dta", separate = FALSE)

## m = % incomplete observations
complete <- complete.cases(br2007)
sum(!complete)/nrow(br2007)*100
## Thus: 30 imputations
set.seed(02138)
br2007.out.30 <- amelia(br2007, m = 30, cs = "CNTRY", ts = "year", polytime = 3, lags = c("ep", "ud_alt", "brr_alt", "tw_alt2", "cbi", "kenwcoor", "benOECD", "unr"), empri = 0.01*nrow(br2007))
write.amelia(obj=br2007.out.30, file.stem = "BR2007 IO Imp Data 30", format = "dta", separate = FALSE)

## HD
br2007.out.hd <- hot.deck(br2007, m = 5)
br2007.out.hd <- hd2amelia(br2007.out.hd)
write.amelia(obj= br2007.out.hd, file.stem = "BR2007 IO Imp Data HD", format = "dta", separate = FALSE)

## MICE
br2007_mice <- mice(br2007, m = 5)
datlist <- mids2datlist(br2007_mice)
br2007_amelia <- list( "imputations"= datlist)
class(br2007_amelia) <- "amelia"
write.amelia(obj= br2007_amelia, file.stem = "BR2007 IO Imp Data MICE", format = "dta", separate = FALSE)
